package com.bjsxt.base.mytest;

import java.util.concurrent.CountDownLatch;

/**
 * 使用枚举类型实现单例模式
 */
public enum SingleInstance {

    UniqueSingleInstance;

    public void testInstance() {
        System.out.println("hash:" + SingleInstance.UniqueSingleInstance.hashCode());
    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(3);

        for (int i = 0; i < 3; i++) {
            SingleInstance.UniqueSingleInstance.testInstance();
            countDownLatch.countDown();
        }
        countDownLatch.await();
        System.out.println("执行完毕");
    }
}
